/**
 * Created by gongxun on 17/4/22.
 */

var KwxDaikaifangWidget = GameBaseWidget.extend({
    Sprite_point : null,

    Image_bg : null,

    mIsShow : null,
    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxDaikaifangWidget.json");
        mo.gameHelper.fixIosText(this.ccsNode);

        this.Sprite_point = mo.seekWidgetByName(this.ccsNode, "Sprite_point");
        this.Image_bg = mo.seekWidgetByName(this.ccsNode, "Image_bg");

        mo.seekWidgetByName(this.ccsNode, "Panel_cut").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)){
                if (this.mIsShow == true){
                    this.setHide();
                }else{
                    this.setShow();
                }
            }
        }, this);
    },

    onEnter: function () {
        this._super();

        mo.eventHelper.add("hideDaikaiFangInfo", this, function(){
            this.setHide();
        });

        this.setShow();
    },

    onExit: function () {
        mo.eventHelper.remove(this);
        this._super();
    },

    setUserInfo : function(user){

        //nick
        var Text_nick = mo.seekWidgetByName(this.ccsNode, "Text_nick");
        mo.gameHelper.setTextString(Text_nick, mo.gameHelper.getUserNickFilterForCount(user.nickname, 3));

        //head
        mo.gameHelper.loadImageForUrl(mo.seekWidgetByName(this.ccsNode, "Image_head"), user.faceUrl);
    },

    setHide : function(){
        if (this.mIsShow == false){
            return;
        }
        this.mIsShow = false;

        this.Image_bg.stopAllActions();
        this.Image_bg.runAction(cc.sequence(
            cc.moveTo(0.2, cc.p(0, 56))
        ));
        this.Sprite_point.setScaleY(-0.3);
    },

    setShow : function(){
        if (this.mIsShow == true){
            return;
        }
        this.mIsShow = true;

        this.Image_bg.stopAllActions();
        this.Image_bg.runAction(cc.sequence(
            cc.moveTo(0.2, cc.p(0, 0))
        ));
        this.Sprite_point.setScaleY(0.3);
    }
});